### -*- coding: utf-8 -*- #############################################
# Разработано Паэглит Арвидом (http://arvid.dp.ua/)
# Все права защищены, 2007
#
# Developed by Paeglit Arvid (http://arvid.dp.ua/)
# All right reserved, 2007
#######################################################################
"""UserAddAnnotation class for the Zope 3 based useraddmail package

$Id: annotation.py 40 2007-12-11 17:09:25Z Arvi3D $
"""
__author__  = "Arvid"
__license__ = "GPL"
__version__ = "$Revision: 40 $"
__date__ = "$Date: 2007-12-11 17:09:25 +0000 (Tue, 11 Dec 2007) $"

from zope.app import zapi
from persistent import Persistent
from zope.interface import implements
from zope.schema.fieldproperty import FieldProperty

from interfaces import IUserAddMail
from ks.channelsmtp.interfaces import IChannelSMTP
from ks.adapter.lazyrequest.interfaces import ILazyRequest

from settings import compress

class UserAddMail(Persistent) :

    implements(IUserAddMail)

    channel = None #FieldProperty(IUserAddMail['channel'])
    ismailable = FieldProperty(IUserAddMail['ismailable'])

    def sendPost(self, user):
        """ send post """

        uniq = compress(user.__name__)
        siteURL = zapi.absoluteURL(zapi.getSiteManager(context = user).__parent__, ILazyRequest(user))
        link = '%s/useractivation.html?uniq=%s' % (siteURL, uniq)
        zapi.getUtility(IChannelSMTP, context = user, name = self.channel).sendTo((user.auth_email, )
                                                                                  ,site = siteURL
                                                                                  ,name = user.auth_name
                                                                                  ,email = user.auth_email
                                                                                  ,link = link
                                                                                  )
